<template>
    <div style="min-width:829px">
        <div v-if="$route.path == '/returnReport'">
            <div class="vs-search-box">
                <el-form ref="form" v-search-box-enter :inline="true" :model="paging" label-width="110px">
                    <el-form-item label="回访人：">
                        <el-select style="width:200px" clearable v-model="paging.staff_id" placeholder="请选择">
                            <el-option v-for="item in shopList" :key="item.id" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="会员卡号：">
                        <el-input v-model="paging.vip_no" placeholder="请输入会员卡号" clearable>
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="姓名：">
                        <el-input v-model="paging.name" placeholder="请输入姓名" clearable>
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="手机号：">
                        <el-input v-model="paging.phone" placeholder="请输入手机号" clearable>
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item class="vs-right-btns">
                        <el-button @click="reset">重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                    <el-form-item label="查询时间段：">
                        <el-date-picker v-model="bill_time_start" type="daterange" format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间"
                            style="width:300px">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <!-- <div class="operation-box clear-float">
                    <el-button style="margin-left:auto;">导出</el-button>
                </div> -->
                <el-table v-loading="loading" :data="tableData" header-row-class-name="has-gutter-table"
                    style="width: 100%" border :key="0">
                    <el-table-column prop="id" label="序号" align="center"></el-table-column>
                    <el-table-column prop="create_time" label="回访日期" align="center"></el-table-column>
                    <el-table-column prop="user.vip_no" label="会员卡号" align="center"></el-table-column>
                    <el-table-column prop="user.realname" label="姓名" align="center"></el-table-column>
                    <el-table-column prop="gender" label="性别" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.user.gender | genderFilter }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="user.phone" label="手机号" align="center"></el-table-column>
                    <el-table-column prop="content" label="回访内容" align="center"></el-table-column>
                    <el-table-column prop="staff.name" label="回访人" align="center"></el-table-column>
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page.sync="paging.page" :page-size="paging.limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="paging.total"
                        :page-sizes="[100, 200, 500, 1000]">
                    </el-pagination>
                </div>
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            shopList: [],
            loading: false,
            bill_time_start: [],
            paging: {
                page: 1,
                total: 0,
                limit: 100,
                staff_id: '',
                vip_no: '',
                name: '',
                phone: '',
            },
            tableData: [],
        };
    },
    filters: {
        genderFilter(val) {
            switch (val) {
                case -1: return '条件限制'
                case 0: return '保密'
                case 1: return '男'
                case 2: return '女'
            }
        }
    },
    created() {
        if (this.$route.path == '/returnReport') {
            this.handleCurrentChange(1);
            this.getStore()
        }
    },
    methods: {
        async getStore() {
            this.loading = true;
            let { code, data } = await this.$Http.getStaff({ is_all: 1 });
            this.loading = false;
            if (code) {
                this.shopList = data;
            }
        },
        async repairGetList() {
            if (!this.bill_time_start) {
                this.bill_time_start = []
            }
            this.paging.date_start = this.bill_time_start[0] || ''
            this.paging.date_end = this.bill_time_start[1] || ''
            let obj = Object.assign({}, this.paging);
            this.loading = true;
            let { code, data } = await this.$Http.getVisituserReport(obj);
            this.loading = false;
            if (code) {
                this.tableData = data.data;
                this.paging.total = data.total;
            }
        },
        reset() {//重置
            this.paging = this.$options.data().paging;
            this.handleCurrentChange(1)
        },
        handleSizeChange(val) {
            this.paging.limit = val;
            this.repairGetList()
        },
        handleCurrentChange(val) {
            this.paging.page = val;
            this.repairGetList()
        }
    },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
    width: 130px;
    height: 130px;
}

.divTable {
    width: 100%;

    div {
        border-bottom: 1px solid #ebeef5;
        border-left: 1px solid #ebeef5;
        border-right: 1px solid #ebeef5;
        height: 50px;
        line-height: 50px;
        padding-left: 30px;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: fixed;

    td {
        border: 1px solid #ebeef5;
        text-align: center;
        height: 32px;
        color: #333333;
        padding: 0 5px;
        font-size: 14px;
    }
}
</style>